const app = getApp();
import { list } from '../../../api/store';

Page({
  data: {
    back: true,
    title: '线下店铺',
    loading: true,
    loadmore: false,
    list: [],
    form: {
      page: 1,
      limit: 10
    },
    abnor: {
      title: '未搜索到店铺信息~',
      button: ''
    }
  },
  onShow() {
    this.setData({
      loading: true,
      list: []
    });
    list(this.data.form).then(res => {
      this.getList(res);
    })
      .finally(() => {
        this.setData({ loading: false });
      });
  },
  onPullDownRefresh() {/*监听用户下拉动作*/ },
  onReachBottom() {
    let form = this.data.form;
    if (form.page == form.last_page) {
      this.setData({ loadmore: true });
    } else {
      form.page += 1;
      list(form).then(res => {
        this.getList(res);
      });
      this.setData({ loadmore: false });
    }
  },

  //===================methon================

  getList(res) {
    let list = this.data.list.concat(res.data.data);
    let form = this.data.form;
    form.last_page = res.data.last_page;
    this.setData({
      list: list,
      form: form,
      loadmore: res.data.last_page <= 1
    });
  },

  call(event) {
    wx.makePhoneCall({
      phoneNumber: event.currentTarget.dataset.telphone
    });
  }
})